Ext.define('Triends.view.Mymessageinfo', {
	requires: ['Triends.view.Othersinfo', 'Triends.view.Sendmessage'],
	extend: 'Ext.Panel',
	xtype: 'msginfo',
	id: 'msginfo',
	config: {
		layout: 'vbox',
		fullscreen: true,
		scrollable: true,
		style: 'background: white;',
		items: [
		{
			xtype: 'panel',
			layout: 'hbox',
			style: 'background:white;margin:10px;border-bottom:1px silver solid',
			height: 30,
			items:[{
				xtype: 'panel',
				width: 100,
				html: '<font size="3">Sender</font>'
			},
			{
				xtype: 'panel',
				width: '100%',
				id: 'msgsenderpanel',
				tpl: ["<a class='Sender'><font size='3'><b>{Sender}</b></font></a>"],
				listeners: {
					tap: {
						element: 'element',
						delegate: 'a.Sender',
						fn: function() {
							var otherid = Ext.getCmp("msgsenderpanel").getData().SenderID;
							openOtherinfo(otherid);
						}
					}
				}
			}]
		},
		{
			xtype: 'panel',
			layout: 'hbox',
			style: 'background:white;margin-left:10px;border-bottom:1px silver solid',
			height: 30,
			items: [{
				xtype: 'panel',
				width: 100,
				html: '<font size="3">Date</font>'
			},
			{
				xtype: 'panel',
				width: '100%',
				id: 'msgtimepanel',
				tpl: ["<font size='3'>{Date}&nbsp;&nbsp;{Time}</font>"]
			}]
		},
		{
			xtype: 'panel',
			id: 'msgpanel',
			style: 'background:white;margin-left:10px;margin-top:20px',
			tpl: ["<font size='3'>{Message}</font>"]
		},
		{
			xtype: 'titlebar',
			docked: 'top',
			height: 40,
			items: [
				{
					xtype: 'button',
					ui: 'small',
					align: 'right',
					width: 50,
					text: '답장',
					handler: function() {
		        		var thisview = Ext.getCmp('msgsenderpanel');
				    	var sender = thisview.getData().Sender;
				    	var getter = thisview.getData().Getter;
				    	var senderID = thisview.getData().SenderID;
				    	var getterID = thisview.getData().GetterID;
				    	
				    	var send = Ext.create('Triends.view.Sendmessage');
				    	var getterpanel = Ext.getCmp('getterpanel');
				    	getterpanel.setData({SenderID: getterID, Sender: getter,  GetterID: senderID, Getter: sender});
				    	send.setData({SenderID: getterID, Sender: getter,  GetterID: senderID, Getter: sender});
				    	Ext.Viewport.add(send);
		    	    }
				},
		 		{
		 			
					xtype: 'button',
					ui: 'small',
					align: 'right',
					width: 50,
					style: 'margin-left:10px',
					text: '삭제',
					handler: function() {
						function msgFunction(buttonIndex){
							if (buttonIndex == 1) {
								Ext.Viewport.setMasked({
									xtype: 'loadmask',
									message: 'Loading...',
									indicator: true
								});
								var thisview = Ext.getCmp('msgsenderpanel');
			    				var num = thisview.getData().Number;
			    	
	    	  					Ext.data.JsonP.request({
	   								url: 'http://itscreater.cafe24.com/Triends/MessageDelete.jsp',
	   								params: {
	   									num : num
	   								},
	          						callbackKey: 'callback',
	          						success: function(result) {
		          				
	          							var userid = Ext.getStore('UserStore').getAt(0).data.ID;
					   			   		
	   			   						var msgStore = Ext.getStore('msgstore');
	            						msgStore.getProxy().setExtraParams({id: userid});
	            						msgStore.load({
	            							callback: function() {
	            								navigator.app.backHistory();
	            								Ext.Viewport.setMasked(false);
	            							}
	            						});
	         						}
	    		  				});	
	   						} else if (buttonIndex == 2) {
   								Ext.emptyFn
   							}
						}
						navigator.notification.confirm(
							'쪽지를 삭제하시겠습니까?',
							msgFunction,
							'알림',
							'OK, Cancel'
						)
		    		}
				}]
		}]
	}
});